﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Campaigns;

@model CampaignListModel


<section id="content_wrapper">

	<!-- Start: Topbar-Dropdown -->
	<div id="topbar-dropmenu">
		@await Html.PartialAsync("_ToolBox")
	</div>
	<!-- End: Topbar-Dropdown -->
	<!-- Start: Topbar -->
	<header id="topbar">
		<div class="topbar-left">
			<ol class="breadcrumb">
				<li class="crumb-active">
					<a href="#">档案</a>
				</li>
				<li class="crumb-icon">
					<a href="@Url.RouteUrl("HomePage")">
						<span class="glyphicon glyphicon-home"></span>
					</a>
				</li>
				<li class="crumb-link">
					<a href="#">商品相关</a>
				</li>
				<li class="crumb-trail">促销活动</li>
			</ol>
		</div>
		<div class="topbar-right">
			<div class="ml15 ib va-m" id="toggle_sidemenu_r">
				<a href="#" class="pl5">
					<i class="fa fa-sign-in fs22 text-primary"></i>
					<span class="badge badge-hero badge-danger">3</span>
				</a>
			</div>
		</div>
	</header>
	<!-- End: Topbar -->
	<!-- Begin: Content -->
	<section id="content" class="formSection">

		<div class="special-alerts">
			<div class="alert alert-danger light alert-dismissable" id="alert-demo-2" style="display: none;">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
				<i class="fa fa-info pr10"></i>
				<strong>您没有被授权此操作!</strong>
			</div>
		</div>

		<div class="row">
			<div class="col-md-12">

				<form class="form-horizontal" asp-action="List" asp-controller="Campaign" method="get" id="formSearch" novalidate="novalidate">
					<div class="panel panel-default" id="panel0">
						<div class="panel-heading">
							<span class="glyphicon glyphicon-search"></span> 高级搜索
							<a class="btn btn-default btn-sm pull-right m5 mrn p5 pbn" id="AdvancedSearch"><i class="fa fa-angle-double-right"></i></a>
						</div>
						<div class="panel-body p10">
							<div class="row">
								<div class="col-sm-2">
									<input asp-for="Name" class="form-control" placeholder="活动名称..." />
								</div>
								<div class="col-sm-2">
									<input asp-for="BillNumber" class="form-control" placeholder="单据编号..." />
								</div>
								<div class="col-sm-2">
									<input asp-for="Remark" class="form-control" placeholder="备注..." />
								</div>
								<div class="col-sm-2">
									<dcms-select asp-for="ChannelId" asp-items="@Model.Channels" asp-default="渠道" />
								</div>
								<div class="col-sm-4">
									<button id="btn_query" type="submit" class="btn btn-primary btn-block">
										<span class="glyphicon glyphicon-search mr5" aria-hidden="true"></span>查询
									</button>
								</div>
							</div>
						</div>
					</div>
				</form>


				<div class="panel">
					<div class="panel-heading">
						<div class="panel-title">
							<span class="glyphicon glyphicon-tasks"></span> 活动列表
						</div>
					</div>
					<div class="panel-body p10">


                        <div class="bootstrap-table">
                            <div class="fixed-table-toolbar">
                                <div class="bs-bars pull-left">
                                    <div id="toolbar" class="btn-group">
                                        <a class="btn btn-primary btn-sm" href="@Url.Action("Create")" target="_blank">
                                            <span class="glyphicon glyphicon-plus mr5" aria-hidden="true"></span>添加
                                        </a>
                                    </div>
                                </div>
                                <div class="columns columns-right btn-group pull-right">
                                    <a class="btn btn-default" title="刷新" href="@Url.Action("List")"><i class="glyphicon glyphicon-refresh icon-refresh"></i></a>
                                </div>
                            </div>
                            <div class="fixed-table-container">
                                <div class="fixed-table-body">

                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                @*<th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; ">
                                <div class="th-inner "><input name="btSelectAll" type="checkbox"></div>
                            </th>*@
                                                <th class="text-center"><div class="th-inner">序号</div></th>
                                                <th class="text-left"><div class="th-inner">促销名称</div></th>
                                                <th class="text-center w150"><div class="th-inner">单据号</div></th>
                                                <th class="text-center w150"><div class="th-inner">TPM协议编码</div></th>
                                                <th class="text-left"><div class="th-inner">渠道</div></th>
                                                <th class="text-center"><div class="th-inner">开始日期</div></th>
                                                <th class="text-center"><div class="th-inner">结束日期</div></th>
                                                <th class="text-right"><div class="th-inner">促销天数</div></th>
                                                <th class="text-right"><div class="th-inner">剩余天数</div></th>
                                                <th class="text-center"><div class="th-inner">状态</div></th>
                                                <th class="text-center"><div class="th-inner">有效</div></th>
                                                <th class="text-left"><div class="th-inner">备注</div></th>
                                                <th class="text-center"><div class="th-inner">操作</div></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @{
                                                int index = 0;
                                                foreach (var item in Model.Items)
                                                {
                                                    <tr>
                                                        @*<td class="bs-checkbox ">
                                        <input data-index="@index" name="btSelectItem" class="btSelectItem" type="checkbox" value="@item.Id">
                                    </td>*@
                                                        <td class="text-center">@item.Id</td>
                                                        <td class="text-left">@item.Name</td>
                                                        <td class="text-center">@item.BillNumber</td>
                                                        <td class="text-center">@item.ProtocolNum</td>
                                                        <td class="text-center">@(string.Join(",", item.Channels.Select(c => c.Name).ToArray()))</td>
                                                        <td class="text-center">
                                                            @item.StartTime.ToString("yyyy-MM-dd hh:mm:ss")
                                                        </td>
                                                        <td class="text-center">
                                                            @item.EndTime.ToString("yyyy-MM-dd hh:mm:ss")
                                                        </td>
                                                        <td class="text-right">
                                                            @item.TotalDay
                                                        </td>
                                                        <td class="text-right">
                                                            @item.ValidlDay
                                                        </td>
                                                        <td class="text-center">
                                                            @Html.Raw(item.Enabled ? "<span class=\"label label-success\">正常</span>" : "<span class=\"label label-default\">弃用</span>")
                                                        </td>
                                                        <td class="text-center">
                                                            @Html.Raw(item.ValidlDay <= 0 ? "<span class=\"label label-danger\">过期</span>" : "<span class=\"label label-default\">有效</span>")
                                                        </td>
                                                        <td class="text-left">
                                                            @item.Remark
                                                        </td>
                                                        <td class="text-center">
                                                            <a class="btn btn-sm btn-primary" data-id="@item.Id" href="@Url.Action("Edit",new { id=item.Id })" title="编辑" target="_blank"><i class="glyphicon glyphicon-pencil mr5"></i> 编辑</a>
                                                            <a class="btn btn-sm btn-danger btn_deletecampaign" data-id="@item.Id" title="删除"><i class="glyphicon glyphicon-remove mr5"></i> 删除</a>
                                                        </td>

                                                    </tr>
                                                    index++;
                                                }

                                            }
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            @{
                                var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                            }

                            @if (!pager.IsEmpty())
                            {
                                <div class="fixed-table-pagination" style="display: block;">
                                    @Html.Raw(pager.ToString())
                                </div>
                            }
                        </div>
						<div class="clearfix"></div>
					</div>
				</div>
			</div>
		</div>


	</section>

	<!-- End: Content -->
</section>



@{ await Html.RenderPartialAsync("_ModalForm", new ViewDataDictionary(ViewData) { { "formId", "UserRoleForm" }, { "showSave", "true" } }); }
@{ await Html.RenderPartialAsync("_ModalForm", new ViewDataDictionary(ViewData) { { "formId", "CombinationModalForm" }, { "modalWindow", "ModalProductWindows" }, { "showSave", "true" } }); }



@section CurPageScripts
{

	<script type="text/javascript">

		jQuery(document).ready(function () {

			"use strict";

			// Init Theme Core
			Core.init();

			// Init Demo JS
			Demo.init();

			//权限提示
			if ($(this).getUrlQueryString("Authorize") == "noAuthorize") {
				$('#alert-demo-2').fadeToggle();
				setTimeout(function () {
					$('#alert-demo-2').fadeToggle();
				}, 3000);
			}

			//全选
			$("input[name='btSelectAll']").click(function () {
				var selectStatus = $(this).is(':checked')
				if (selectStatus) {
					$("input[name='btSelectItem']").each(function (i, n) {
						n.checked = true;
					});
				} else {
					$("input[name='btSelectItem']").each(function (i, n) {
						n.checked = false;
					});
				}
			});

			//高级搜索
			$("#panel0 #AdvancedSearch").click(function () {
				var ico = $(this).find(".fa");
				if (ico.hasClass('fa-angle-double-right'))
					ico.removeClass("fa-angle-double-right").addClass("fa-angle-double-down");
				else
					ico.removeClass("fa-angle-double-down").addClass("fa-angle-double-right");
				$("#panel0").find(".panel-body").toggleClass("hidden fadeIn");
			});


			//日期选择控件初始
			$('.datetimepicker').datetimepicker({ locale: 'zh-cn' });


			//删除
			$(".btn_deletecampaign").click(function ()
            {
				var id = $(this).attr("data-id");
                WinMsg.confirm({ message: "确认要删除选择的数据吗？" }).on(function (e) {
                    if (!e) {
                        return;
					}
					location.href = "@Url.Action("Delete")?id=" + id;
                });
            });

			//防止重复查询
			var queryNumber = 1;
			$("#btn_query").click(function () {
				if (queryNumber > 1) {
					return false;
				}
				queryNumber = queryNumber + 1;
			});

		});
	</script>
}
